package com.yale.action;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

/**
 * Created by yale on 2017/10/20.
 * struts2的action用于接收客户请求
 * 如果该action要实现该功能,必须实现struts2的action接口
 *
 */
public class LoginAction implements Action {
    private String username;
    private String password;
    private String msg;

    @Override
    public String execute() throws Exception {
        System.err.println("LoginAction来了");

        //可以调用service,dao,...
        //处理客户请求的数据

        //判断为空,返回到登陆页面
        //通过setter注入,自动传值,不需要request.getParameter()获取了
        if(null == this.getUsername() || "".equals(this.getUsername())){
            return LOGIN;
        }else{
            this.setMsg("登陆成功-zhang");
            ActionContext.getContext().getSession().put("CURRENT_USER", this.getUsername());
        }

        //处理完毕后要返回到前端JSP页面
        return SUCCESS;
    }

    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
}
